home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / eiffel / smalleif.97 / se.t / SmallEiffel / lib_test / test_dictionary.e < prev    next >
Encoding:
Text File  |  1996-05-02  |  2.6 KB  |  124 lines

  1. -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C) 
  2. -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
  3. --
  4. class TEST_DICTIONARY
  5.  
  6. creation {ANY}
  7.    make
  8.    
  9. feature {ANY}
  10.    
  11.    k1: STRING is "k1";
  12.    k2: STRING is "k2";
  13.    k3: STRING is "k3";
  14.    k4: STRING is "k4";
  15.  
  16.    v1: STRING is "v1";
  17.    v2: STRING is "v2";
  18.    v3: STRING is "v3";
  19.    v4: STRING is "v4";
  20.  
  21.    make is
  22.       local
  23.      d: DICTIONARY[STRING,STRING];
  24.      k, v: STRING;
  25.      i: INTEGER;
  26.      v_list, k_list: ARRAY[STRING];
  27.       do
  28.          !!d.make;
  29.          is_true(d.count = 0);
  30.          is_true(d.empty);
  31.          is_true(not d.has(k1));
  32.  
  33.          d.put(v1,k1);
  34.          is_true(d.count = 1);
  35.          is_true(not d.empty);
  36.          is_true(d.has(k1));
  37.          is_true(not d.has(k2));
  38.          is_true(d @ k1 = v1);
  39.          is_true(d.at(k1) = v1);
  40.          is_true(d.at("k1") = v1);
  41.          is_true(d.item(1) = v1);
  42.  
  43.          d.put(v2,k2);
  44.          is_true(d.count = 2);
  45.          is_true(not d.empty);
  46.          is_true(d.has("k1"));
  47.          is_true(d.has("k2"));
  48.          is_true(not d.has("k3"));
  49.          is_true(d @ k1 = v1);
  50.          is_true(d.at(k2) = v2);
  51.          is_true(d.item(1) = v1 or d.item(1) = v2);
  52.          is_true(d.item(2) = v1 or d.item(2) = v2);
  53.      is_true(d.key_at(v1) = k1);
  54.      is_true(d.key_at(v2) = k2);
  55.      
  56.          d.put(v3,k3);
  57.          d.put(v4,k4);
  58.      from  
  59.         v_list := <<v1,v2,v3,v4>>;
  60.         k_list := <<k1,k2,k3,k4>>;
  61.         i := 1;
  62.      invariant
  63.         v_list.count = k_list.count;
  64.      variant
  65.         v_list.count - 1
  66.      until
  67.         i > d.count     
  68.      loop
  69.         v := d.item(i);
  70.         k := d.key(i);
  71.         v_list.remove(v_list.fast_index_of(v));
  72.         k_list.remove(k_list.fast_index_of(k));
  73.         i := i + 1
  74.      end;
  75.      is_true(v_list.empty);
  76.      is_true(k_list.empty);
  77.      
  78.      from  
  79.         v_list := <<v1,v2,v3,v4>>;
  80.         k_list := <<k1,k2,k3,k4>>;
  81.         i := 1;
  82.      invariant
  83.         v_list.count = k_list.count;
  84.      variant
  85.         v_list.count
  86.      until
  87.         i > d.count     
  88.      loop
  89.         v := d.item(i);
  90.         k := d.key_at(v);
  91.         v_list.remove(v_list.fast_index_of(v));
  92.         k_list.remove(k_list.fast_index_of(k));
  93.         i := i + 1
  94.      end;
  95.      is_true(v_list.empty);
  96.      is_true(k_list.empty);
  97.      
  98.      is_true(d.count = 4);
  99.      d.remove(k1);
  100.      is_true(d.count = 3);
  101.      d.remove(k2);
  102.      is_true(d.count = 2);
  103.      d.remove(k3);
  104.      is_true(d.count = 1);
  105.      d.remove(k4);
  106.      is_true(d.count = 0);
  107.       end;
  108.    
  109.    is_true(b: BOOLEAN) is
  110.       do
  111.      cpt := cpt + 1;
  112.      if not b then
  113.         std_output.put_string("TEST_DICTIONARY: ERROR Test # ");
  114.         std_output.put_integer(cpt);
  115.         std_output.put_string("%N");
  116.      else
  117. --        std_output.put_string("Yes%N");
  118.      end;
  119.       end;
  120.    
  121.    cpt: INTEGER;
  122.    
  123. end -- TEST_DICTIONARY
  124.